package com.xingda.packing.dmds.config;

import java.util.concurrent.Executors;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.SubscriberExceptionContext;
import com.google.common.eventbus.SubscriberExceptionHandler;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration("eventBusDMDSConfig")
public class EventBusConfig {

	@Bean("eventBusDMDS")
	public EventBus eventBus() {
		return new AsyncEventBus(Executors.newScheduledThreadPool(10), new EventBusConfig.SubscriberException());
	}

	class SubscriberException implements SubscriberExceptionHandler {

		@Override
		public void handleException(Throwable exception, SubscriberExceptionContext context) {
			log.error("事件触发出错{}", exception.getMessage());
		}

	}

}
